$(function() {
	$('#tt').edatagrid({
		onClickRow : function(index, row) {
			 if(checkEnding()){
				 editIndex = index;
	         }
			if (row.loginType != 1 && row.loginType != 13) {
				$('#tt').datagrid('selectRow',index).datagrid('beginEdit',index)
				endEditing(index, 'payRate');
				endEditing(index, 'payMin');
				endEditing(index, 'payMax');
			}
		},
		onAfterEdit : function(rowIndex, rowData, changes) {
			$.ajax({
				url : '/apkconfig/saveLoginType',
				data : rowData,
				type : 'POST'
			/*
			 * complete : function(xhr) {
			 * ajaxobj=eval("("+xhr.responseText+")");
			 * $.messager.alert("添加登录方式", ajaxobj.return_msg); }
			 */
			});
		},
		onCancelEdit:function(index,row){
			row.editing = false;
			$('#tt').datagrid('updateRow',{
				index: index,
				row:{}
			});
		}
	})
	
	 var editIndex = undefined;
	 function checkEnding(){
         if(editIndex == undefined) {
        	 return true;
         }
         if($('#tt').datagrid('validateRow',editIndex)) {
             $('#tt').datagrid('endEdit',editIndex);
             editIndex = undefined; 
             return true;
          }else{
        	  return false;
          }
      }

	
	function endEditing(index, field){
		var cellEdit = $('#tt').datagrid('getEditor', {
			index : index,
			field : field
		});
		var $input = cellEdit.target; 
		$input.attr("disabled", true);
	}

	// 输入框数字限制，最大为100且只最多能有两位小数点
	$(document).on(
			"keyup afterpaste",
			"td[field='rate'] input",
			function(e) {
				this.value = this.value.replace(/[^\d.]/g, ""); // 清除“数字”和“.”以外的字符
				this.value = this.value.replace(/\.{2,}/g, "."); // 只保留第一个.
																	// 清除多余的
				this.value = this.value.replace(".", "$#$").replace(/\./g, "")
						.replace("$#$", ".");
				this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,
						'$1$2.$3');// 只能输入两个小数
				if (this.value.indexOf(".") < 0 && this.value != "") {// 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于
																		// 01、02的金额
					this.value = parseFloat(this.value);
				}
				if (this.value > 100) {
					this.value = 100;
				}
			})

});

function formatterLoginType(value, row, index) {
	return row.loginName;
}
